package com.example.demo.controller.people;

import com.example.demo.model.ResponseMessage;
import com.example.demo.model.people.Provider;
import com.example.demo.service.people.ProviderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/provider")


public class ProviderController {
    @Autowired
    private ProviderService service;

//    @RequestMapping("getByProviderId")
//    @ResponseBody
//    List<Provider> getByProviderId(Integer id){return service.getByProviderId(id);}

    @RequestMapping("save")
    public ResponseMessage save(Provider provider){
        ResponseMessage responseMessage = new ResponseMessage();
        Boolean flag = service.save(provider);
        responseMessage.setFlag(flag);

        return  responseMessage;
    }

    @RequestMapping("selectAll")
    @ResponseBody
    public List<Provider> selectAll(){ return service.selectAll(); }

    @RequestMapping("addProvider")
    public Integer addProvider(Provider provider){return service.addProvider(provider);}

    @RequestMapping("deleteById")
    public Boolean deleteById(Integer id){return service.deleteById(id)==1;}

    @RequestMapping("updateById")
    public Integer updateById(Provider provider ){return service.updateById(provider);}

    @RequestMapping("findProvider")
    public List<Provider> findProvider(String  providername,String  connectionperson,String  phone){return service.findProvider(providername,connectionperson,phone);};

}
